commit: Add --editor / -e command line argument
authorMathnerd314 <mathnerd314.gph+hs@gmail.com>
Mon, 23 May 2016 18:44:36 +0000 (12:44 -0600)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 25 May 2016 18:37:47 +0000 (18:37 +0000)
Previously, the behavior was to run the editor if no subject or body was specified.
This led to using commit -s '' in scripts, to avoid running the editor.
In practice, manually editing commit messages is rare, whereas automated scripting
is common, so instead default to not running the editor and only run it when -e
is given.

Closes: #305
Approved by: cgwalters

src/ostree/ot-builtin-commit.c

index a021fbfa470545f67cf53dfa4bbcd6424e87a307..5acd0243c456a29d0044addf67cf22ac5bc5b63d 100644 (file)
@@ -32,6 +32,7 @@
 
 static char *opt_subject;
 static char *opt_body;
+static gboolean opt_editor;
 static char *opt_parent;
 static gboolean opt_orphan;
 static char *opt_branch;
@@ -73,6 +74,7 @@ static GOptionEntry options[] = {
   { "parent", 0, 0, G_OPTION_ARG_STRING, &opt_parent, "Parent ref, or \"none\"", "REF" },
   { "subject", 's', 0, G_OPTION_ARG_STRING, &opt_subject, "One line subject", "SUBJECT" },
   { "body", 'm', 0, G_OPTION_ARG_STRING, &opt_body, "Full description", "BODY" },
+  { "editor", 'e', 0, G_OPTION_ARG_NONE, &opt_editor, "Use an editor to write the commit message", NULL },
   { "branch", 'b', 0, G_OPTION_ARG_STRING, &opt_branch, "Branch", "BRANCH" },
   { "orphan", 0, 0, G_OPTION_ARG_NONE, &opt_orphan, "Create a commit without writing a ref", NULL },
   { "tree", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_trees, "Overlay the given argument as a tree", "dir=PATH or tar=TARFILE or ref=COMMIT" },
@@ -425,7 +427,7 @@ ostree_builtin_commit (int argc, char **argv, GCancellable *cancellable, GError
         goto out;
     }
 
-  if (!opt_subject && !opt_body)
+  if (opt_editor)
     {
       if (!commit_editor (repo, opt_branch, &opt_subject, &opt_body, cancellable, error))
         goto out;